_package("alz.mui");

_import("alz.mui.Component");

/**
 * 支持action机制的组件基类
 */
_class("ActionElement", Component, function(){
	this._init = function(){
		_super._init.call(this);
		this._actionManager = null;
		this._action = "";
		this._timer = 0;  //计时器，防止用户多次重复点击
	};
	this.init = function(obj){
		_super.init.apply(this, arguments);
		this._action = this._self.getAttribute("_action");
	};
	this.dispose = function(){
		this._actionManager = null;
		_super.dispose.apply(this);
	};
	this.getActionManager = function(){
		return this._actionManager;
	};
	this.setActionManager = function(v){
		this._actionManager = v;
	};
	this.getAction = function(){
		return this._action;
	};
	this.setAction = function(v){
		if(this._action == v) return;
		this._action = v;
		if(this._self){
			this._self.setAttribute("_action", v);
		}
	};
	this.dispatchAction = function(sender, ev){
		if(this._disabled) return false;
		var d = new Date().getTime();
		if(this._timer != 0){
			if(d - this._timer <= 500){  //两次点击间隔必须大于500毫秒
				runtime.log("[ActionElement::dispatchAction]cancel");
				this._timer = d;
				return false;
			}
		}
		this._timer = d;
		return this._actionManager.dispatchAction(this._action, sender, ev);
	};
});